{% macro headers(grid, definition, request_attributes) %}
    {% import '@SyliusShop/shared/macro/grid/table/sorting.html.twig' as sorting %}

    {% if definition.actionGroups.bulk is defined and definition.getEnabledActions('bulk')|length > 0 %}
        <th class="w-1">
            <input data-js-bulk-checkboxes=".bulk-select-checkbox" data-js-bulk-buttons=".sylius-grid-nav__bulk" type="checkbox" class="form-check-input">
        </th>
    {% endif %}

    {% for field in definition.fields|sylius_sort_by('position') %}
        {% if field.enabled %}
            {% if field.isSortable %}
                {{ sorting.table_header(grid, field, request_attributes) }}
            {% else %}
                <th class="text-body sylius-table-column-{{ field.name }}">{{ field.label|trans }}</th>
            {% endif %}
        {% endif %}
    {% endfor %}
    {% if definition.actionGroups.item is defined and definition.getEnabledActions('item')|length > 0 %}
        <th class="w-1 text-body text-center sylius-table-column-actions">{{ 'sylius.ui.actions'|trans }}</th>
    {% endif %}
{% endmacro %}

{% macro row(grid, definition, row) %}
    <tr class="item" {{ sylius_test_html_attribute('row') }}>
        {% if definition.actionGroups.bulk is defined and definition.getEnabledActions('bulk')|length > 0 %}
            <td class="center aligned"><input class="form-check-input" type="checkbox" value="{{ row.id }}" /></td>
        {% endif %}
        {% for field in definition.enabledFields|sylius_sort_by('position') %}
            <td>{{ sylius_grid_render_field(grid, field, row) }}</td>
        {% endfor %}
        {% if definition.actionGroups.item is defined and definition.getEnabledActions('item')|length > 0 %}
            <td {{ sylius_test_html_attribute('actions') }}>
                <div class="d-flex gap-1 justify-content-end">
                    {% for action in definition.getEnabledActions('item')|sylius_sort_by('position') %}
                        {{ sylius_grid_render_action(grid, action, row) }}
                    {% endfor %}

                    {% if definition.actionGroups.subitem is defined and definition.getEnabledActions('subitem')|length > 0 %}
                        {% set subactions %}
                            {% for action in definition.getEnabledActions('subitem')|sylius_sort_by('position') %}
                                {{ sylius_grid_render_action(grid, action, row) }}
                            {% endfor %}
                        {% endset %}
                        {% if subactions|trim|length > 0 %}
                            <div class="dropdown">
                                <div data-bs-toggle="dropdown">
                                    <button class="btn btn-sm btn-outline-gray dropdown-static" data-bs-toggle="tooltip" data-bs-title="{{ 'sylius.ui.more'|trans }}">
                                        {{ ux_icon('tabler:dots', { class: 'icon icon-sm flex-shrink-0' }) }}
                                    </button>
                                </div>

                                <div class="dropdown-menu dropdown-menu-end">
                                    {{ subactions }}
                                </div>
                            </div>
                        {% endif %}
                    {% endif %}
                </div>
            </td>
        {% endif %}
    </tr>
{% endmacro %}
